package stores;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class PasswordMangler {

	public static String mangle(String jelszo) {
		MessageDigest messageDigest = null;
		try {
			messageDigest = MessageDigest.getInstance("SHA-256");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		messageDigest.update(jelszo.getBytes());
		return new String(messageDigest.digest());
	}

	public static boolean isValid(String jelszo, String jelszoHash) {
		String loginHash = PasswordMangler.mangle(jelszo);
		return MessageDigest.isEqual(jelszoHash.getBytes(),
				loginHash.getBytes());
	}

	public static void main(String args[]) {
		System.out.println(PasswordMangler.mangle("Password1"));
		System.out.println(PasswordMangler.mangle("Password2"));
		System.out.println(PasswordMangler.mangle("a"));
		System.out.println(PasswordMangler.mangle("b"));
	}

}
